/**
 * 
 */
package com.zj.helloview.editor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

import com.zj.helloview.model.Category;

/**
 * @author Administrator
 *
 */
public class CategoryEditor extends EditorPart {

	public static final String ID = "com.zj.helloview.category.editor";
	private Category cat;
	private String categoryName;
	private CategoryEditorInput input;

	// Will be called before createPartControl
	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		if (!(input instanceof CategoryEditorInput)) {
			throw new RuntimeException("Wrong input");
		}

		CategoryEditorInput new_name = (CategoryEditorInput) input;
		this.input = (CategoryEditorInput) input;
		setSite(site);
		setInput(input);
		categoryName = this.input.getCategoryName();
		setPartName("categoryName: " + categoryName);
	}

	@Override
	public void createPartControl(Composite parent) {
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		parent.setLayout(layout);
		Label label1 = new Label(parent, SWT.NONE);
		label1.setText("category Name");
		Text text = new Text(parent, SWT.BORDER);
		text.setText(categoryName);
		text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
		
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// person.getAddress().setCountry(text2.getText());
	}

	@Override
	public void doSaveAs() {
	}

	@Override
	public boolean isDirty() {

		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}

	@Override
	public void setFocus() {
	}

}
